package com.springBoot.springBootSysCore.modules.enums.base;

import com.springBoot.springBootSysCore.common.utils.enumUtils.EnumFindHelper;
import com.springBoot.springBootSysCore.common.utils.enumUtils.EnumKeyGetter;
import com.springBoot.springBootSysCore.common.utils.enumUtils.EnumKeyVal;

import java.util.List;

/**
 * 用户类型
 * Created by timo on 2017/11/28.
 */
public enum UserTypeEnum {

    /**
     * 未支付:0
     */
    NOMAL("普通用户", "0"),
    /**
     * 已支付:1
     */
    TEACHER("老师", "1"),

    ADMIN("管理员","2");

    private String name;
    private String val;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String getVal() {
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }

    private UserTypeEnum(String name, String val) {
        this.name = name;
        this.val = val;
    }


    static final EnumFindHelper<UserTypeEnum, String> keyHelperT =
            new EnumFindHelper<UserTypeEnum, String>(UserTypeEnum.class, new UserTypeEnum.KeyGetter());
    static final EnumFindHelper<UserTypeEnum, String> keyHelper =
            new EnumFindHelper<UserTypeEnum, String>(UserTypeEnum.class, new UserTypeEnum.KeyGetter(), new UserTypeEnum.ValGetter());

    static final EnumFindHelper<UserTypeEnum, String> valHelperT =
            new EnumFindHelper<UserTypeEnum, String>(UserTypeEnum.class,new UserTypeEnum.ValGetter());
    static final EnumFindHelper<UserTypeEnum, String> valHelper =
            new EnumFindHelper<UserTypeEnum, String>(UserTypeEnum.class,new UserTypeEnum.ValGetter(), new UserTypeEnum.KeyGetter());

    static class KeyGetter implements EnumKeyGetter<UserTypeEnum, String> {
        @Override
        public String getKey(UserTypeEnum enumValue) {
            return enumValue.name;
        }
    }
    static class ValGetter implements EnumKeyGetter<UserTypeEnum, String> {
        @Override
        public String getKey(UserTypeEnum enumValue) {
            return enumValue.val;
        }
    }
    public static UserTypeEnum valfindT(String name, UserTypeEnum defaultValue){
        return keyHelperT.findT(name, defaultValue);
    }
    public static UserTypeEnum nameFindT(String val, UserTypeEnum defaultValue){
        return valHelperT.findT(val, defaultValue);
    }
    public static Object valfind(String name, String defaultValue){
        return keyHelper.find(name, defaultValue);
    }
    public static Object nameFind(String val, String defaultValue){
        return valHelper.find(val, defaultValue);
    }
    public static List<EnumKeyVal> keyValList(){
        return keyHelper.keyValList();
    }

}
